<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>配置管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
<style type="text/css">
  .loadingImg {
	background: url('../images/loading1.gif');
	height:60px;
	width:60px;
	background-repeat: no-repeat;
	margin-left:250px;  
    margin-top : 200px;
  }
</style>
<script type="text/javascript">
$(document).ready(function() {
	
	    var $el = $('<div></div>').addClass('om-widget-overlay') //蒙版
				.css({
					width: $(window).width(),
					height: $(window).height()
				}).append($('<div></div>').addClass('loadingImg'));
	
      	$('#deviceTree_t').omTree({
      		dataSource : 'reOrDeTe!queryAll.do',
            widht : 500,
            showCheckbox : true,
            onBeforeExpand : function(node){
            	$el.appendTo(document.body);
            	var nodeDom = $("#"+node.nid);
            	if(nodeDom.hasClass("hasChildren") && nodeDom.children("ul").children().length == 0){
            		nodeDom.removeClass("hasChildren");
            		$.ajax({
                        url: 'reOrDeTe!queryAll.do?queryId='+node.id,
                        method: 'POST',
                        dataType: 'json',
                        success: function(data){
                            $("#deviceTree_t").omTree("insert", data, node);
                            $el.remove();
                        }
                    });
            	}else{
            		$el.remove();
            	}
            	return true;
            },
            onClick:function(){
            	$('#root').parent().removeClass('selected');
            },
            onCheck: function(nodeData){
            	var checked = $('#deviceTree_t').omTree('getChecked',true);
            	var ids = '';
            	for(var i=0 ;i<checked.length ; i++){
            		if(checked[i].id.indexOf('te_' == -1)){ //终端不计算在内
	            		ids +=checked[i].id+',';
            		}
            	}
            	$('#selectedIds').val(ids); //将选中的节点一并返回，后台处理是设置刷卡终端还是摄像头终端
			}
      	});
      	
        $('#root').click(function(){
  		  $(this).parent().addClass('selected');
  		  $('#deviceTree_t').find('span.selected').removeClass('selected');
  	  });
      	
      	 $('#deviceregions').omCombo({
             dataSource : 'reOrDeTe!findRegions.do',
             onValueChange : function(target, newValue, oldValue) {
                 getOrganizationRecords();
             }
         });
      	$('#deviceregions').bind('change',function(){
      	    if($('#deviceregions').val() == ''){
      	    	$('#deviceregions').omCombo('value','');
      	    }
      	})
      	 
      	 $('#deviceorganization').omCombo({
             dataSource : 'reOrDeTe!findOrganizations.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
                 if($('#deviceorganization').val() == ''){
                	 $('#deviceorganization').omCombo('value','');
                 }
             }
         });
      	$('#deviceorganization').bind('change',function(){
      	    if($('#deviceorganization').val() == ''){
      	    	$('#deviceorganization').omCombo('value','');
      	    }
      	})
      	 $('#devicedevice').omCombo({
             dataSource : 'reOrDeTe!findDevices.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
             }
         });
      	$('#devicedevice').bind('change',function(){
      	    if($('#devicedevice').val() == ''){
      	    	$('#devicedevice').omCombo('value','');
      	    }
      	})
      	 function getOrganizationRecords(){
      		var regions = $('#deviceregions').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findOrganizations.do',
                data : {regionsId : regions},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#deviceorganization').val('').omCombo('setData', data);
                	$('#devicedevice').val('').omCombo( 'setData', []);
                	$('#deviceorganization').omCombo('value','');
                	$('#devicedevice').omCombo('value','');
                }
            });
      	 }
      	 
      	 function getDevice(){
      		var organization = $('#deviceorganization').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findDevices.do',
                data : {organizationId : organization},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#devicedevice').val('').omCombo('setData', data);
                }
            });
      	 }
      	 
      	 $('#deviceserachTree').click(function(){
      		$el.appendTo(document.body);
      		var regions = $('#deviceregions').omCombo('value');
      		var organization = $('#deviceorganization').omCombo('value');
      		var device = $('#devicedevice').omCombo('value');
      		if(device){
      			queryTreeData('de_'+device);
      		}else if(organization){
      			queryTreeData('or_'+organization);
      		}else if(regions){
      			queryTreeData('re_'+regions);
      		}else{
      			queryTreeData(null);
      		}
      	 });
      	 
      	 function queryTreeData(id){
      		$('#deviceTree_t').omTree('setData' , 'reOrDeTe!queryAll.do?queryId='+id);
			$('#deviceTree_t').omTree('refresh');
			$el.remove();
      	 }
      	 
      	$("#paramAccessEditor").omDialog({
        	autoOpen: false,
  		    height: 350,
  		    width : 480,
  		    modal: true,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#paramAccessForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#paramAccessEditor" ).omDialog("close");
              }
          }]
        });
      	
      	$("#paramCameraEditor").omDialog({
        	autoOpen: false,
  		    height: 520,
  		    width : 480,
  		    modal: true,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#paramCameraForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#paramCameraEditor" ).omDialog("close");
              }
          }]
        });
      	
      	$('#paramAccessSetting').click(function(){
      		$('#paramAccessForm').resetForm();
      		var selects = $("#selectedIds").val(); //如果选择两个以上的记录，则为批量设置，不会读取出记录
      		var ida = selects?selects.split(','):null;
        	if(ida && ida.length > 2){ //批量设置
        		$("#paramAccessEditor").omDialog('open');
        	}else if(ida && ida.length == 2 && ida[1] == ''){ //单个设置，如果有记录先读取
        		$.ajax({
        			url : 'terminalSetting!findByAccessTerminalId.do',
        			data : {accessTerminalId : ida[0]},
        			dataType : 'json',
        			success : function(data){
        				if(data){
        					$('#paramsAccessName').val(data.name);
	        				$('#paramsAccessUser').val(data.userName);
	        				$('#paramsAccessPwd').val(data.pwd);
	        				$('#di1').val(data.di1);
	        				$('#di2').val(data.di2);
	        				$('#do1').val(data.do1);
	        				$('#do2').val(data.do2);
	        				$('#paramsAccessmanagerServerIp').val(data.managerServerIp);
        				}
        				$("#paramAccessEditor").omDialog('open');
        			}
        		});
        	}else{
        		$.omMessageTip.show({timeout : 2000,content : '请选择终端！',type : 'error'});
        	}
      	});
      	$('#paramCameraSetting').click(function(){
      		$('#paramCameraForm').resetForm();
      		var selects = $("#selectedIds").val(); //如果选择两个以上的记录，则为批量设置，不会读取出记录
      		var ida = selects?selects.split(','):null;
        	if(ida && ida.length > 2){ //批量设置
        		$("#paramCameraEditor").omDialog('open');
        	}else if(ida && ida.length == 2 && ida[1] == ''){ //单个设置，如果有记录先读取
        		$.ajax({
        			url : 'terminalSetting!findByCameraTerminalId.do',
        			data : {cameraTerminalId : ida[0]},
        			dataType : 'json',
        			success : function(data){
        				if(data){
                            $('#paramCameraName').val(data.name);
	        				$('#protocolId').val(data.protocolId);
	        				$('#protocolAddress').val(data.protocolAddress);
	        				$('#protocolMode').val(data.protocolMode);
	        				$('#motionAreaRange1').val(data.motionAreaRange1);
	        				$('#motionAreaSst1').val(data.motionAreaSst1);
	        				$('#presetDefaultAddress').val(data.presetDefaultAddress);
	        				$('#protocolSpeed').val(data.protocolSpeed);
							$('#paramCameraUser').val(data.userName);
	        				$('#paramCameraPwd').val(data.pwd);
	        				$('#paramCameraDi1').val(data.di1);
							$('#paramCameraDi2').val(data.di2);
	        				$('#paramCameraDo1').val(data.do1);
	        				$('#paramCameraDo2').val(data.do2);
							$('#managerServerIp').val(data.managerServerIp);
        				}
        				$("#paramCameraEditor").omDialog('open');
        			}
        		});
        	}else{
        		$.omMessageTip.show({timeout : 2000,content : '请选择终端！',type : 'error'});
        	}
      	});
      	
   	  $('#paramAccessForm').submit(function() {
             $(this).omAjaxSubmit({
             	url : 'terminalSetting!saveParamAccess.do',
       		    data: {terminalId: $('#selectedIds').val()},
                success : function(data){
                   	if(data == '1'){ 
                       	$('#paramAccessEditor').omDialog('close');
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }});
             return false;//返回false,阻止浏览器默认行为
         });
   	  
   	  $('#paramCameraForm').submit(function() {
             $(this).omAjaxSubmit({
             	url : 'terminalSetting!saveParamCamera.do',
       		    data: {terminalId: $('#selectedIds').val()},
                success : function(data){
                   	if(data == '1'){ 
                       	$('#paramCameraEditor').omDialog('close');
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }});
             return false;//返回false,阻止浏览器默认行为
         });
});

</script>   
  </head>
  
  <body>
  <div class="select_table">


<table   cellpadding="0" cellspacing="0" class="layout"  >

          <tr>
            <td width="5%" align="right">区域：</td>
            <td width="12%">
              <input name="regions" id="deviceregions" type="text"/>
            </div></td>
            <td width="5%" align="right">组织：</td>
            <td width="12%">
              <input name="organization" id="deviceorganization" type="text"/>
            </div></td>
            <td width="5%" align="right">设备：</td>
            <td width="12%">
              <input name="device" id="devicedevice" type="text"/>
            </div></td>
            <td>
            <td align="left">
            <button class="button_u" id="deviceserachTree" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">查询</button></td>
            </td>
          </td>
          </tr>
          </table>
</div>
    <div class="toolbar mar">
      <a href="#" class="rbutton" id="paramAccessSetting"><span><img src="../images/add.gif" width="14" height="14" /><ins>刷卡终端参数设置</ins></span></a>
	  <a  class="line"></A>
      <a href="#" class="rbutton" id="paramCameraSetting"><span><img src="../images/add.gif" width="14" height="14" /><ins>摄像终端参数设置</ins></span></a>
    </div>
	<div class="catalogTree">
     <ul class="om-tree om-widget">
	     <li class="om-tree-node collapsable">
	        <div class="hitarea om-tree-node-hitarea -hitarea collapsable-hitarea"></div>
	        <span class="folder selected"><a href="#"  id="root">根节点</a></span>
	        <ul id="deviceTree_t"></ul>
	     </li>
	  </ul>
	</div>
	 <input type="hidden" id="selectedIds" name="selectedIds"> <!-- 选中的id,以逗号分隔 -->
	<div id="paramAccessEditor" title="刷卡终端参数设置" style="display: none;">
     <form id="paramAccessForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="14%" align="right">名称：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="text" name="paccess.name" id="paramsAccessName" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">用户：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.userName" id="paramsAccessUser" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">密码：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.pwd" id="paramsAccessPwd" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输入1：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.di1" id="di1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输入2：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.di2" id="di2" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输出1：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.do1" id="do1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输出2：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.do2" id="do2" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">前置主机ip地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="paccess.managerServerIp" id="paramsAccessmanagerServerIp" class="input_text"/>
               </td>
             </tr>
           </table>
         </form>
   </div>
   
   <div id="paramCameraEditor" title="摄像终端参数设置" style="display: none;">
     <form id="paramCameraForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="14%" align="right">名称：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="text" name="pcmera.name" id="paramCameraName" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">ptz协议序号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.protocolId" id="protocolId" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">协议地址序号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.protocolAddress" id="protocolAddress" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">协议方式：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.protocolMode" id="protocolMode" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">移动侦测矩形坐标：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.motionAreaRange1" id="motionAreaRange1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">移动侦测灵敏度：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.motionAreaSst1" id="motionAreaSst1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">预制位默认地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.presetDefaultAddress" id="presetDefaultAddress" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">ptz转速：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.protocolSpeed" id="protocolSpeed" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">用户名：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.userName" id="paramCameraUser" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">密码：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.pwd" id="paramCameraPwd" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输入1：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.di1" id="paramCameraDi1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输入2：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.di2" id="paramCameraDi2" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输出1：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.do1" id="paramCameraDo1" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">io输出2：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.do2" id="paramCameraDo2" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">前置主机ip地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pcmera.managerServerIp" id="managerServerIp" class="input_text"/>
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
